/**
 * Utility functions.
 */
public class Utils
{
    /**
     * Append string represenation of object to the buffer, delimiting if needed.
     */
    public static void append(StringBuffer buffer, Object item, String delimiter)
    {
        String repr = item.toString();
        if (buffer.length() > 0 && !repr.isEmpty())
            buffer.append(delimiter);
        buffer.append(item);
    }

    /**
     * Join sequence to delimited string.
     */
    public static String join(Iterable items, String delimiter)
    {
        StringBuffer buffer = new StringBuffer();
        for (Object item : items)
            append(buffer, item, delimiter);
        return buffer.toString();
    }

    public static class Pair<F, S>
    {
        /**
         * First element of pair.
         */
        public F first;

        /**
         * Second element of pair.
         */
        public S second;


        public Pair(F first, S second)
        {
            this.first = first;
            this.second = second;
        }
    }
}
